package com.woniu.service.impl;

import com.woniu.entity.Reward1;
import com.woniu.mapper.RewardDao;
import com.woniu.pojo.Reward;
import com.woniu.pojo.RewardExample;
import com.woniu.service.RewardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class RewardServiceImpl implements RewardService {
    @Autowired
    RewardDao rewardDao;
    @Override
    public void add(Reward reward) {
        rewardDao.insert(reward);
    }

    @Override
    public void deleteById(Integer rewardId) {
    rewardDao.deleteByPrimaryKey(rewardId);
    }

    @Override
    public Reward findOne(Integer rewardId) {
        return rewardDao.selectByPrimaryKey(rewardId);
    }

    @Override
    public void updateById(Reward reward) {
    rewardDao.updateByPrimaryKey(reward);
    }

    @Override
    public List<Reward> findAll() {
        return rewardDao.selectByExample(null);
    }

    @Override
    public void deleteByExample(List<Integer> asList) {
        RewardExample rewardExample=new RewardExample();
        rewardExample.createCriteria().andRewardIdIn(asList);
        rewardDao.deleteByExample(rewardExample);
    }

    @Override
    public List<Reward1> findAll1() {
        return rewardDao.selectByExample1(null);
    }

    @Override
    public List<Reward1> findDate(Map<String, Object> mapCondition) {
        RewardExample rewardExample=new RewardExample();
        RewardExample.Criteria criteria = rewardExample.createCriteria();
        Reward reward = (Reward) mapCondition.get("reward");
        if (reward.getClassId()!=null&&reward.getClassId()!=0){
            criteria.andClassIdEqualTo(reward.getClassId());
        }
        if (reward.getStudentId()!=null&&reward.getStudentId()!=0){
            criteria.andStudentIdEqualTo(reward.getStudentId());
        }
        return rewardDao.selectByExample1(rewardExample);
    }
}
